/************************************************************************
 * AIDE/Tools - Automata Identification Engine
 * Copyright (C) 2012-2013 Ali Khalili (khalili_DOT_ir_@SIGN_gmail_DOT_com)
 * **********************************************************************
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License (LGPL) published 
 * by the Free Software Foundation; either version 2.1 of the License, or (at your
 * option) any later version. This program is distributed without any
 * warranty. See the GNU Lesser General Public License for more details. 
 * ***********************************************************************
 * File         :     
 * Description  :     
 * Change log   :     	-Date:  Change
 ************************************************************************/

using System;
using System.Reflection;
using SMLib.Automata.MM;
using SMLib.Automata.IA;

namespace LearnIt
{
	/// <summary>
	/// Load SUL object
	/// </summary>
	public class LoadSUL
	{
		Assembly asm;

		/// <summary>
		/// Initializes a new instance of the <see cref="SUT.LoadSUL"/> class.
		/// </summary>
		/// <param name="path">Path of library (usually a dll file)</param>
		public LoadSUL (string path)
		{
			asm=Assembly.LoadFrom(path);						
			if(asm==null)
				throw new Exception("The library "+path+"is not there!");		
		}

		/// <summary>
		/// Load the specified class
		/// </summary>
		/// <param name="cls">Name of the class which implements<see cref="IBlackBox_MM"/> </param>
		public IBlackBox_MM LoadMealy(string cls)
		{			
			Type t =asm.GetType(cls);
			if(t==null)
				throw new Exception("The class "+cls+" is not there!");
			
			MethodInfo m = t.GetMethod("CreateInstance",BindingFlags.Static|BindingFlags.Public);
			if(m==null)
				throw new Exception("The create method is not there!");
			
			object o = m.Invoke(null,null);
			return (IBlackBox_MM)o;
		}	


		public IBlackBox_IA LoadIA(string cls)
		{			
			Type t =asm.GetType(cls);
			if(t==null)
				throw new Exception("The class "+cls+" is not there!");

			MethodInfo m = t.GetMethod("CreateInstance",BindingFlags.Static|BindingFlags.Public);
			if(m==null)
				throw new Exception("The create method is not there!");

			object o = m.Invoke(null,null);
			return (IBlackBox_IA)o;
		}	
			
	}
}

